package com.xxgc.cloud.error.center.error;

import com.xxgc.cloud.error.center.BaseException;
import com.xxgc.cloud.error.center.GlobalException;
import com.xxgc.cloud.error.center.exception.NotQuartzClassFoundException;
import com.xxgc.cloud.error.center.exception.QuartzTimeException;
import com.xxgc.cloud.error.center.result.ErrResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @program: SpringCloudStudy
 * @description: Quartz异常
 * @author: Mr.abel(ShiJiaYi)
 * @create: 2022-11-23 16:16
 **/
@Slf4j
@ControllerAdvice
@ResponseBody
public class QuartzException extends GlobalException {
    /**
     * 创建定时器异常
     * @param e
     * @return6
     */
    @ExceptionHandler(value = {QuartzTimeException.class})
    public ErrResult<BaseException> quartzTimeException(QuartzTimeException e){
        log.error(e.toString());
        String msg = active.equals(myActive) ? system : e.getDefaultMessage();
        return active.equals(myActive) ? ErrResult.error(msg,e.getCode()) : ErrResult.error(msg,e.getCode(),e);
    }

    @ExceptionHandler(value = NotQuartzClassFoundException.class)
    public ErrResult<BaseException> notQuartzClassFoundException(NotQuartzClassFoundException e){
        log.error(e.toString());
        String msg = active.equals(myActive) ? system : e.getDefaultMessage();
        return active.equals(myActive) ? ErrResult.error(msg,e.getCode()) : ErrResult.error(msg,e.getCode(),e);
    }
}
